package com.ruoyi.vegetable.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.vegetable.domain.ExVegetable;
import com.ruoyi.vegetable.service.IExVegetableService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 蔬菜管理-子菜单Controller
 * 
 * @author 2702梁家琦
 * @date 2024-04-18
 */
@RestController
@RequestMapping("/vegetable/vegetable")
public class ExVegetableController extends BaseController
{
    @Autowired
    private IExVegetableService exVegetableService;

    /**
     * 查询蔬菜管理-子菜单列表
     */
    @PreAuthorize("@ss.hasPermi('vegetable:vegetable:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExVegetable exVegetable)
    {
        startPage();
        List<ExVegetable> list = exVegetableService.selectExVegetableList(exVegetable);
        return getDataTable(list);
    }

    /**
     * 导出蔬菜管理-子菜单列表
     */
    @PreAuthorize("@ss.hasPermi('vegetable:vegetable:export')")
    @Log(title = "蔬菜管理-子菜单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExVegetable exVegetable)
    {
        List<ExVegetable> list = exVegetableService.selectExVegetableList(exVegetable);
        ExcelUtil<ExVegetable> util = new ExcelUtil<ExVegetable>(ExVegetable.class);
        util.exportExcel(response, list, "蔬菜管理-子菜单数据");
    }

    /**
     * 获取蔬菜管理-子菜单详细信息
     */
    @PreAuthorize("@ss.hasPermi('vegetable:vegetable:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(exVegetableService.selectExVegetableById(id));
    }

    /**
     * 新增蔬菜管理-子菜单
     */
    @PreAuthorize("@ss.hasPermi('vegetable:vegetable:add')")
    @Log(title = "蔬菜管理-子菜单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExVegetable exVegetable)
    {
        return toAjax(exVegetableService.insertExVegetable(exVegetable));
    }

    /**
     * 修改蔬菜管理-子菜单
     */
    @PreAuthorize("@ss.hasPermi('vegetable:vegetable:edit')")
    @Log(title = "蔬菜管理-子菜单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExVegetable exVegetable)
    {
        return toAjax(exVegetableService.updateExVegetable(exVegetable));
    }

    /**
     * 删除蔬菜管理-子菜单
     */
    @PreAuthorize("@ss.hasPermi('vegetable:vegetable:remove')")
    @Log(title = "蔬菜管理-子菜单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(exVegetableService.deleteExVegetableByIds(ids));
    }
}
